<?php
    include_once('lang.php');
    $home_nav = '';
    $profile_nav = '';
    $project_nav = ' class="current"';
    $product_nav = '';
    $contact_nav = '';
    
    if(isset($_GET['project_cat']) && in_array($_GET['project_cat'],array(1,2,3,4,5))){
        $project_cat = $_GET['project_cat'];
    }else{
        $project_cat = 1;
    }
    
    $project_0_nav = '';
    $project_1_nav = '';
    $project_2_nav = '';
    $project_3_nav = '';
    $project_4_nav = '';
    $project_5_nav = '';
    
    switch($project_cat){
        case 1:
            $project_1_nav = ' class="current"';
            $page_title = __l('project-house-title');
            break;
        case 2:
            $project_2_nav = ' class="current"';
            $page_title = __l('project-condo-title');
            break;
        case 3:
            $project_3_nav = ' class="current"';
            $page_title = __l('project-office-title');
            break;
        case 4:
            $project_4_nav = ' class="current"';
            $page_title = __l('project-hotel-title');
            break;
        case 5:
            $project_5_nav = ' class="current"';
            $page_title = __l('project-other-title');
            break;
    }
    
    $lang_redirect_page_ = 'project.php?'.$_SERVER["QUERY_STRING"];
    
    include('header.php');
    include('function/function.php');
    
    $con = db_connect();
    $sql = "SELECT * FROM projects WHERE project_cat_id=$project_cat ORDER BY project_id DESC";
    $result = mysql_query($sql);
    
    if(mysql_num_rows($result)>=1){
    $i = 1;
    $project_lits = '';
    while($row=mysql_fetch_assoc($result)){
	
	if(file_exists('images/projects/'.$row['project_id'].'/'.$row['project_img']) && trim($row['project_img'])!=''){
	    $img__ = $row['project_id'].'/'.$row['project_img'];
	}else{
	    $img__ = 'no-pic.jpg';
	}
        
        if(strlen($row['project_title'])<=15){
            $project_title_caption = $row['project_title'];
        }else{
            $project_title_caption = substr_utf8($row['project_title'],0,15);
        }
	
	if($i==1){
	    $project_lits .=<<<showcase_lits
	    <li id="{$row['project_id']}">
		<img src="images/projects/{$img__}" alt="{$row['project_title']}" class="project_gallery thumb_active" />
		<div class="project_thumb_gallery_list_caption">{$project_title_caption}</div>
	    </li>
showcase_lits;
	    $project_id = $row['project_id'];
	    
	    if($_SESSION['lang']=='th'){
		$project_date = get_thai_date(date("F j Y",strtotime($row['project_date'])));
	    }else{
		$project_date = date("F j Y",strtotime($row['project_date']));
	    }
	    
	    $project_detail_title = $row['project_title'];
	    
	    if($row['project_area']>0){
		$project_area  = $row['project_area'];
		$projectarea = __l('project-area');
	    }else{
		$project_area = __l('no-project-area');
		$projectarea = '';
	    }
	    
	    if(trim($row['project_owner'])!=''){
		$project_owner  = $row['project_owner'];
	    }else{
		$project_owner  = __l('no-project-owner');
	    }
	    
	    if(trim($row['project_complete_year'])!=''){
		$project_complete_year  = $row['project_complete_year'];
	    }else{
		$project_complete_year  = __l('no-project-complete-year');
	    }
	    
	    if($row['project_value']>0){
		$project_value  = number_format($row['project_value'], 0, '.', ',');
		$projectvalue = __l('project-value');
	    }else{
		$project_value = __l('no-project-value');
		$projectvalue = '';
	    }
	    
	    
	    $project_detail_img = "images/projects/".$row['project_id']."/".$row['project_img'];
            
            if(file_exists('images/projects/'.$row['project_id'].'/'.$row['project_cert']) && trim($row['project_cert'])!=''){
                $project_cert = '<a href="images/projects/'.$row['project_id'].'/'.$row['project_cert'].'" class="certColorBox"><img src="images/cert_bt_'.$_SESSION['lang'].'.png" alt="Certificate"/></a>';
            }else{
                $project_cert = '';
            }
	    
	    if($row['project_img']!='' && file_exists( "images/projects/".$row['project_id']."/big_".$row['project_img'])){
		$project_img_first = $row['project_id'].'/big_'.$row['project_img'];
	    }else if($row['project_img']!='' && file_exists( "images/projects/".$row['project_id']."/".$row['project_img'])){
		$project_img_first = $row['project_id'].'/'.$row['project_img'];
	    }else{
		$project_img_first = 'no-pic.jpg';
	    }
	    
	}else{
	    $project_lits .=<<<showcase_lits
	    <li id="{$row['project_id']}">
		<img src="images/projects/{$img__}" alt="{$row['project_title']}" class="project_gallery" />
		<div class="project_thumb_gallery_list_caption">{$project_title_caption}</div>
	    </li>
showcase_lits;
	}
	
	$i++;
    }
    //$project_lits .= $project_lits;
    //$project_lits .= $project_lits;
    //$project_lits .= $project_lits;
    
    $sql = "SELECT * FROM project_img WHERE project_id=$project_id AND project_img_show=1 ORDER BY img_position";
    $result = mysql_query($sql);
    $i = 1;
    $project_img_lits = '';
    
    while($row=mysql_fetch_assoc($result)){
	if(file_exists('images/projects/'.$project_id.'/'.$row['project_img_path']) && trim($row['project_img_path'])!=''){
            if($i==1){
                $project_img_lits .=<<<showcase_lits
                    <li id="{$row['project_img_id']}">
                        <img src="images/projects/{$project_id}/{$row['project_img_path']}" alt="{$project_detail_title}" class="project_thumb_gallery thumb_active" />
                    </li>
showcase_lits;
		
		$project_img_first = $project_id.'/'.$row['project_img_path'];
            }else{
                $project_img_lits .=<<<showcase_lits
                    <li id="{$row['project_img_id']}">
                        <img src="images/projects/{$project_id}/{$row['project_img_path']}" alt="{$project_detail_title}" class="project_thumb_gallery" />
                    </li>
showcase_lits;
            }
            
            $i++;
        }
    }
    
    if($i==1){
	$project_img_lits_display = ' class="display_none"';
    }else{
	$project_img_lits_display = '';
    }
?>
    <div id="project_l">
	<table style="width:100%;">
	    <tr>
		<td style="vertical-align:middle;text-align:center;width:100%;height:260px;">
		    <img src="images/projects/<?php echo $project_img_first; ?>" alt="<?php echo $project_detail_title; ?>" id="project_img" />
		</td>
	    </tr>
	</table>
    </div>
    <div id="project_r">
        <div id="project_r_detail">
            <p id="project_r_detail_date"><?php echo $project_date; ?>  //</p>
            <h3 id="project_r_detail_title"><?php echo $project_detail_title; ?></h3>
            <p id="project_r_detail_">
                <span class="span_owner-title"><?php _l('project-area-title'); ?> : </span><?php echo $project_area; ?> <?php $projectarea; ?><br />
                <span class="span_owner span_owner-title span_owner_<?php echo $lang; ?>"><?php _l('project-owner-title'); ?> : </span><span class="owner-title owner-title-project-page"><?php echo $project_owner; ?></span>
		<br />
                <span class="span_owner-title"><?php _l('project-complete-title'); ?> : </span><?php echo $project_complete_year; ?><br />
                <span class="span_owner-title"><?php _l('project-value-title'); ?> : </span><?php echo $project_value; ?> <?php $projectvalue; ?><br />
            </p>
            <div id="project_cert"><?php echo $project_cert; ?></div>
        </div>
        <div id="project_r_thumb">
            <div id="project_r_thumb_next">
                <img src="images/project_r_thumb_next.jpg" alt="Previous" id="project_ctrl_prev"<?php echo $project_img_lits_display; ?> />
            </div>
            <div id="project_r_thumb_list">
                <ul<?php echo $project_img_lits_display; ?>>
                    <?php echo $project_img_lits; ?>
                </ul>
            </div>
            <div id="project_r_thumb_prev">
               <img src="images/project_r_thumb_prev.jpg" alt="Next" id="project_ctrl_next"<?php echo $project_img_lits_display; ?> />
            </div>
            <div class="clear">&nbsp;</div>
        </div>
    </div>
    <div class="clear">&nbsp;</div>
    
    <div id="project_list_box" class="content_box png_bg">
        <h2><?php echo $page_title; ?></h2>
        
        <div id="project_list_prev">
            <img src="images/project_r_thumb_next.jpg" alt="Previous" class="project_list_prev"/>
        </div>
        <div id="project_list">
            <ul>
                <?php echo $project_lits; ?>
            </ul>
        </div>
        <div id="project_list_next">
           <img src="images/project_r_thumb_prev.jpg" alt="Next" class="project_list_next"/>
        </div>
        <div class="clear">&nbsp;</div>
    </div>
    <script type="text/javascript" src="js/jquery.jcarousel.min.js"></script>
    <script>
        function mycarousel_initCallback(carousel) {
	    jQuery('#project_ctrl_next').bind('click', function() {
		carousel.next();
		return false;
	    });
	
	    jQuery('#project_ctrl_prev').bind('click', function() {
		carousel.prev();
		return false;
	    });
	};
        
        function mycarousel_initCallback2(carousel) {
	    jQuery('.project_list_next').bind('click', function() {
		carousel.next();
		return false;
	    });
	
	    jQuery('.project_list_prev').bind('click', function() {
		carousel.prev();
		return false;
	    });
	};
        
        function project_thumb_gallery(){
	    jQuery("#project_r_thumb_list").jcarousel({
		scroll: 1,
		wrap: 'circular',
		initCallback: mycarousel_initCallback,
		// This tells jCarousel NOT to autobuild prev/next buttons
		buttonNextHTML: null,
		buttonPrevHTML: null,
                itemFallbackDimension : 63
	    });
	}
        
        $(document).ready(function(){
            jQuery("#project_r_thumb_list").jcarousel({
		scroll: 1,
		wrap: 'circular',
		initCallback: mycarousel_initCallback,
		// This tells jCarousel NOT to autobuild prev/next buttons
		buttonNextHTML: null,
		buttonPrevHTML: null,
                itemFallbackDimension : 63
	    });
           
           jQuery("#project_list").jcarousel({
		scroll: 1,
		wrap: 'circular',
		initCallback: mycarousel_initCallback2,
		// This tells jCarousel NOT to autobuild prev/next buttons
		buttonNextHTML: null,
		buttonPrevHTML: null,
                itemFallbackDimension : 113
	    });
           
	    $('.project_thumb_gallery').live('click',function(){
		var thisEle = $(this);
		$('.project_thumb_gallery').removeClass('thumb_active');
		thisEle.addClass('thumb_active');
                $('#project_img').attr('src',$(this).attr('src'));
	    });
           
	    $('#project_list ul li').live('mouseenter',function(){
		$(this).find('.project_thumb_gallery_list_caption').fadeOut('fast');
	    });
           
	    $('#project_list ul li').live('mouseleave',function(){
		$(this).find('.project_thumb_gallery_list_caption').fadeIn('fast');
	    });
           
           $('.project_thumb_gallery_list_caption,.project_gallery').click(function(){
		var thisEle = $(this);
		$('.project_gallery').removeClass('thumb_active');
		thisEle.parent().find('img').addClass('thumb_active');
                
		$.post("function/project_load.php", { "project_id": thisEle.parent('li').attr('id') },function(data){
                    $('#project_r_thumb_list').html(data.project_thumb_list);
                    $('#project_img').attr('src',data.project_img);
		    $('#project_r_detail_date').html(data.project_r_detail_date);
		    $('#project_r_detail_title').html(data.project_r_detail_title);
		    $('#project_r_detail_').html(data.project_r_detail_);
                    $('#project_cert').html(data.project_cert);
		    if(data.project_thumb_list_show_slide==1){
			$('#project_ctrl_prev').css('display','block');
			$('#project_ctrl_next').css('display','block');
		    }else{
			$('#project_ctrl_prev').css('display','none');
			$('#project_ctrl_next').css('display','none');
		    }
		    project_thumb_gallery();
		}, "json");
	    });
	   
	    if($(window).height()<580){
		$("#main_bg").height(580);
		$("#main_bg").css('overflowY','hidden');
		$("#main_bg").css('display','block');
	    }else{
		$("#main_bg").height($(window).height());
		$("#main_bg").css('overflowY','hidden');
		$("#main_bg").css('display','block');
		$("#footer").css('position','absolute');
		$("#footer").css('bottom','0');
	    }
        });
    </script>
<?php
    }else{
	echo '<div id="no_product">COMING SOON</div>';
?>
	<script>
	    $(document).ready(function(){
		if($(window).height()<580){
		    $("#main_bg").height(580);
		    $("#main_bg").css('overflowY','hidden');
		    $("#main_bg").css('display','block');
		}else{
		    $("#main_bg").height($(window).height());
		    $("#main_bg").css('overflowY','hidden');
		    $("#main_bg").css('display','block');
		}
		
		$("#footer").css('position','absolute');
		$("#footer").css('bottom','0');
		$("#no_product").css('marginTop',($(window).height()/2)-270);
		$("#footer").css('bottom','0');
	    });
	</script>
<?php
    }
    db_close($con);
    include('footer.php');
?>